<template>
    <!-- <van-pull-refresh v-model="isLoading" @refresh="onRefresh"> -->
        <div class="my">
            <div class="my_information_topWarp">
                <div class="my_information_back" >
                    <span class="my_information_title">我的</span>
                </div>
            </div>
            <div class="my_information_main">
                <div class="my_information">
                    <van-image round width="1.4rem" height="1.4rem" :src="logoUrl" />
                    <div class="information">
                        <div class="information_userName"> <span>用户：{{ userName || '--' }}</span>  </div>
                    </div>
                </div>
                <!-- 修改信息 -->
                 <div class="my_information_edit">
                    <van-cell-group>
                        <van-cell title="修改账号"  is-link >
                        <!-- <van-cell title="修改账号"  is-link  @click="goMyinformation()"> -->
                            <template #icon>
                                <van-image :src="zhanghaoIcon" style="width: 17px; height: 15px;"/>
                              </template>
                        </van-cell>
                        <van-cell title="修改密码"  is-link  @click="goChangePassword()">
                        <!-- <van-cell title="修改密码"  is-link  > -->
                            <template #icon>
                                <van-image :src="mimaIcon" style="width: 17px; height: 15px;"/>
                              </template>
                        </van-cell>
                        <van-cell title="关于元表记"  is-link  @click="goAbout()">
                            <template #icon>
                                <van-image :src="about" style="width: 17px; height: 15px;"/>
                              </template>
                        </van-cell>
                      </van-cell-group>
                 </div>
                 <!-- 退出登录 -->
                  <div  class="my_info_loginout">
                    <van-button block type="primary" class="btn1" @click="LoginOut"> 退出登录 </van-button>
                  </div>

                
            </div>
        </div>
    <!-- </van-pull-refresh> -->
</template>

<script>
import { onMounted, reactive, ref, toRefs } from 'vue'
import { Toast, Dialog, Notify } from 'vant';
import { useStore } from "vuex"; // ⚪️ 引入状态管理
import { useRoute, useRouter } from "vue-router";
import router from "@/router";
// import { GetMemberExt } from "@/network/user";
import logoUrl from '@/assets/img/my/avatar.png'
import zhanghaoIcon from '@/assets/img/my/zhanghao-icon.png'
import mimaIcon from '@/assets/img/my/mima-icon.png'
import about from '@/assets/img/my/about.png'
import user from '../store/modules/user';
export default {
    setup() {
        const store = useStore(); // 获取对象
        const state = reactive({
            token: store.state.user.token,
            userName: store.state.user.name,
            isLoading: false,
            logoUrl: logoUrl,
            userInfo: {},
            zhanghaoIcon:zhanghaoIcon,
            mimaIcon:mimaIcon,
            about:about
            // MemberExt: {}
        });
        onMounted(() => {
            // state.userName = store.state.user.name;
            // init();
            
        });
        // 初始化信息
        const init = () => {
            getUser();
        };
        //获取用户信息 
        const getUser = () => {
            store.dispatch("GetMemberInfo").then((res) => {
                console.log('获取用户信息',res.data[0].children[0]);
                
            }).catch(() => { });
        }
        // 刷新页面
        const onRefresh = () => {
            init()
            state.isLoading = false
        }
        // 退出登录
        const LoginOut = () => {
            Dialog.confirm({
                title: '提示',
                message: '确定要退出登录吗？',
            }).then(() => {
                const toast = Toast.loading({
                    duration: 0,
                    forbidClick: true,
                    message: '退出登录中...',
                });
                // 调用action的登录方法
                store.dispatch("LoginOut", {}).then((res) => {
                    router.push({ path: "/Home", });
                    toast.clear()
                }).catch(() => {
                    toast.clear()
                });
            }).catch(() => { });
        }
        // 修改密码页面
        const goChangePassword = () => {
            router.push({
                path: "/changePassword",
                query: {
                    date: new Date().getTime()
                }
            });
        };
        // 关于元表记页面
        const goAbout = () => {
            router.push({
                path: "/about",
                query: {
                    date: new Date().getTime()
                }
            });
        };
        return {
            ...toRefs(state),
            getUser,
            LoginOut,
            onRefresh,
            goChangePassword,goAbout
        };
    },
};
</script>

<style scoped></style>